Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports System.IO

Namespace Phoenix.Tools.Backup
	Public Class FilePage : Inherits Phoenix.Tools.WizardPageBase
		Private lblDescription As System.Windows.Forms.Label
		Private lblFile As System.Windows.Forms.Label
		Private WithEvents txtPath As System.Windows.Forms.TextBox
		Private WithEvents btnBrowse As System.Windows.Forms.Button
		Private fileDialog As System.Windows.Forms.OpenFileDialog
		Private labelComment As System.Windows.Forms.Label
		Private folderBrowserDialog As System.Windows.Forms.FolderBrowserDialog
		Private components As System.ComponentModel.IContainer = Nothing

		Public Sub New()
			' This call is required by the Windows Form Designer.
			InitializeComponent()

		End Sub

		''' <summary>
		''' Clean up any resources being used.
		''' </summary>
		Protected Overrides Overloads Sub Dispose(ByVal disposing As Boolean)
			If disposing Then
				If Not components Is Nothing Then
					components.Dispose()
				End If
			End If
			MyBase.Dispose(disposing)
		End Sub

		#Region "Designer generated code"
		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FilePage))
			Me.lblDescription = New System.Windows.Forms.Label()
			Me.lblFile = New System.Windows.Forms.Label()
			Me.txtPath = New System.Windows.Forms.TextBox()
			Me.btnBrowse = New System.Windows.Forms.Button()
			Me.fileDialog = New System.Windows.Forms.OpenFileDialog()
			Me.labelComment = New System.Windows.Forms.Label()
			Me.folderBrowserDialog = New System.Windows.Forms.FolderBrowserDialog()
			Me.SuspendLayout()
			' 
			' lblDescription
			' 
			Me.lblDescription.Location = New System.Drawing.Point(24, 8)
			Me.lblDescription.Name = "lblDescription"
			Me.lblDescription.Size = New System.Drawing.Size(448, 40)
			Me.lblDescription.TabIndex = 1
			Me.lblDescription.Text = "To perform backing up or restoring operations you must specify the backup file lo" & "cation."
			' 
			' lblFile
			' 
			Me.lblFile.Location = New System.Drawing.Point(24, 58)
			Me.lblFile.Name = "lblFile"
			Me.lblFile.Size = New System.Drawing.Size(96, 14)
			Me.lblFile.TabIndex = 2
			Me.lblFile.Text = "Backup &Directory:"
			' 
			' txtPath
			' 
			Me.txtPath.Location = New System.Drawing.Point(120, 56)
			Me.txtPath.Name = "txtPath"
			Me.txtPath.Size = New System.Drawing.Size(352, 20)
			Me.txtPath.TabIndex = 4
			Me.txtPath.Text = ""
'			Me.txtPath.TextChanged += New System.EventHandler(Me.txtPath_TextChanged);
			' 
			' btnBrowse
			' 
			Me.btnBrowse.FlatStyle = System.Windows.Forms.FlatStyle.System
			Me.btnBrowse.Location = New System.Drawing.Point(400, 80)
			Me.btnBrowse.Name = "btnBrowse"
			Me.btnBrowse.TabIndex = 5
			Me.btnBrowse.Text = "&Browse"
'			Me.btnBrowse.Click += New System.EventHandler(Me.btnBrowse_Click);
			' 
			' fileDialog
			' 
			Me.fileDialog.DefaultExt = "BAK"
			Me.fileDialog.Filter = "Backup files|*.bak|All files|*.*"
			Me.fileDialog.Title = "Choose a backup file"
			' 
			' labelComment
			' 
			Me.labelComment.Location = New System.Drawing.Point(64, 112)
			Me.labelComment.Name = "labelComment"
			Me.labelComment.Size = New System.Drawing.Size(376, 16)
			Me.labelComment.TabIndex = 6
			Me.labelComment.Text = "Please note: the backup file must be located in the SQL Server file system"
			Me.labelComment.Visible = False
			' 
			' FilePage
			' 
			Me.Controls.Add(Me.labelComment)
			Me.Controls.Add(Me.btnBrowse)
			Me.Controls.Add(Me.txtPath)
			Me.Controls.Add(Me.lblFile)
			Me.Controls.Add(Me.lblDescription)
			Me.Description = "Choose a file to back up Agronaut database or restore from."
			Me.HeaderImage = (CType(resources.GetObject("$this.HeaderImage"), System.Drawing.Image))
			Me.Index = 3
			Me.Name = "FilePage"
			Me.Size = New System.Drawing.Size(924, 678)
			Me.Title = "Choose a backup file"
'			Me.Next += New Phoenix.Tools.WizardForm.WizardNextEventHandler(Me.FilePage_Next);
			Me.ResumeLayout(False)

		End Sub
		#End Region

		Private Sub btnBrowse_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
'			if(fileDialog.ShowDialog() == DialogResult.OK)
'				txtPath.Text = fileDialog.FileName;
			If folderBrowserDialog.ShowDialog() = DialogResult.OK Then
				txtPath.Text = folderBrowserDialog.SelectedPath
			End If
		End Sub

		Public Manager As OperationManager

		Protected Friend Overrides Sub OnPageShown()
			txtPath_TextChanged(txtPath, Nothing)
'			btnBrowse.Enabled = (Manager.DBServer == @"(local)\Phoenix");
'			labelComment.Visible = (Manager.DBServer != @"(local)\Phoenix");

		End Sub

		Private Sub txtPath_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPath.TextChanged
			If Manager.BackupMode Then
				If txtPath.Text="" Then
					WizardPageParent.WizardButtons = WizardForm.TWizardsButtons.Previous Or WizardForm.TWizardsButtons.Cancel
				Else
					WizardPageParent.WizardButtons = WizardForm.TWizardsButtons.AllShort
				End If
			Else
				If txtPath.Text="" OrElse (Manager.DBServer="(local)" AndAlso (Not Directory.Exists(txtPath.Text))) Then
					WizardPageParent.WizardButtons = WizardForm.TWizardsButtons.Previous Or WizardForm.TWizardsButtons.Cancel
				Else
					WizardPageParent.WizardButtons = WizardForm.TWizardsButtons.AllShort
				End If
			End If
		End Sub

        Private Sub FilePage_Next(ByVal sender As Object, ByVal e As Phoenix.Tools.WizardForm.EventNextArgs) Handles MyBase.NextEvent
            Dim folder As String = txtPath.Text
            Manager.BackupDirectory = folder
            Manager.BackupFile = Path.Combine(folder, "PhoenixDB.bak")
            Manager.DefaultPath = txtPath.Text
        End Sub

        Private Sub FilePage_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            txtPath.Text = Manager.DefaultPath
        End Sub
    End Class
End Namespace

